<html>
<head><meta charset="utf-8"><title>Comparing &amp;&amp;str and &amp;str · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html">Comparing &amp;&amp;str and &amp;str</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225881405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Comparing%20%26%26str%20and%20%26str/near/225881405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html#225881405">(Feb 10 2021 at 18:03)</a>:</h4>
<p>What is the reason this code does not compile? It seems that comparing &amp;&amp;str and a &amp;str is not possible, but I can't explain why. Is this a necessary limitation or just a papercut?<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a8be370ff6fbef602c04b32d409a814c">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a8be370ff6fbef602c04b32d409a814c</a></p>



<a name="225882990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Comparing%20%26%26str%20and%20%26str/near/225882990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html#225882990">(Feb 10 2021 at 18:15)</a>:</h4>
<p>(Simple repro: <code>&amp;2 == &amp;&amp;2</code>)<br>
Directly, PartialEq on references is <code>&amp;T: PartialEq&lt;&amp;T&gt;</code>.<br>
Is there a different way?  Dunno.</p>
<p>You might be interested in <a href="https://github.com/rust-lang/rust/issues/44619">https://github.com/rust-lang/rust/issues/44619</a>, which had some discussions of stuff that are sortof related but nothing ended up happening.</p>



<a name="225885709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Comparing%20%26%26str%20and%20%26str/near/225885709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html#225885709">(Feb 10 2021 at 18:34)</a>:</h4>
<p>yeah this is a papercut, no it's not a necessary one</p>



<a name="225906221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Comparing%20%26%26str%20and%20%26str/near/225906221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html#225906221">(Feb 10 2021 at 20:54)</a>:</h4>
<p>Yeah, this has been a long-standing pet peeve of mine</p>



<a name="225906279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Comparing%20%26%26str%20and%20%26str/near/225906279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html#225906279">(Feb 10 2021 at 20:55)</a>:</h4>
<p>luckily many PartialEq impls for std types have been filled out since then so it's no longer as painful as it used to be</p>



<a name="225985615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Comparing%20%26%26str%20and%20%26str/near/225985615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Comparing.20.26.26str.20and.20.26str.html#225985615">(Feb 11 2021 at 12:58)</a>:</h4>
<p>Perhaps we can detect this case and issue a note about how to fix it? Not exactly sure what the right herustic would be though...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>